#!/usr/bin/python3
# -*- coding: utf8 -*-
# Date   : 2021/02/24
# Author : Kwan
# Email  : allenxian@live.com
# Blog   : https://my.oschina.net/u/4173440

import OPi.GPIO as GPIO
import orangepi.zero
from Reader import MFCReader
from time import sleep


def gpio_init():
    """
    GPIO初始化
    """
    GPIO.cleanup()
    GPIO.setmode(orangepi.zero.BOARD)
    GPIO.setwarnings(False)
    # 复位读卡器
    GPIO.setup(22, GPIO.OUT, GPIO.HIGH)

try:
    gpio_init()
    print(f"GPIO初始化成功")
    reader = MFCReader()
    print(f"读卡器初始化成功")
    while True:
        card_info = reader.read_card()
        if card_info:
            print(f"读卡信息 => {card_info}")
        sleep(0.25)
except Exception as e:
    print(f"运行失败：{e}")
finally:
    GPIO.cleanup()
    print("程序退出")

